<?php

class sfGuardGroupPermissionForm extends BaseFormDoctrine
{

	public function setup()
	{
		$this->setWidgets(array(
			'group_id' => new WidgetFormHiddenInfo(array('model' => 'sfGuardGroup', 'column' => 'name','label' => 'Grupo')),
			'permission_id' => new sfWidgetFormDoctrineChoice(array('model' => 'sfGuardPermission', 'label' => 'Permiso', 'order_by' => array('name', 'asc')))
		));

		$this->setValidators(array(
			'permission_id' => new sfValidatorDoctrineChoice(array('model' => 'sfGuardPermission', 'required' => true)),
			'group_id' => new sfValidatorDoctrineChoice(array('model' => 'sfGuardGroup', 'required' => true))
		));

		$validator = new ValidatorCombinedKey(array('model' => $this->getModelName(), 'display_column' => 'permission_id'));
		$validator->setMessage('invalid', 'El permiso ya se ha dado al grupo');
		$this->validatorSchema->setPostValidator($validator);

		$this->widgetSchema->setNameFormat('sf_guard_group_permission[%s]');

		$this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

		$this->setupInheritance();

		parent::setup();
	}

	public function getModelName()
	{
		return 'sfGuardGroupPermission';
	}

}
